#include "TDxBuffer.h"

HRESULT TDxBuffer::Create(	ID3D10Device* pDevice,
							UINT iSize, 
							UINT iCounter, 
							void* pPoint, 
							UINT  BindFlags,
							D3D10_USAGE Usage,
							ID3D10Buffer** ppGetBuffer )
{
	assert( pPoint || iCounter > 0 );
	HRESULT hr;

	ID3D10Buffer**  ppBuffer = ppGetBuffer;
	
	if( ppBuffer == NULL ) 
	{
		ppBuffer = &m_pBuffer;
	}

	m_iCount = iCounter;

    m_BufferDesc.Usage			= Usage;
    m_BufferDesc.ByteWidth		= iSize * iCounter;
    m_BufferDesc.BindFlags		= BindFlags;
	if( Usage == D3D10_USAGE_DYNAMIC)
		m_BufferDesc.CPUAccessFlags	= D3D10_CPU_ACCESS_WRITE;
	else
		m_BufferDesc.CPUAccessFlags	= 0;
    m_BufferDesc.MiscFlags		= 0;

	ZeroMemory( &m_SubResourceData, sizeof( D3D10_SUBRESOURCE_DATA ) );
    m_SubResourceData.pSysMem	 = pPoint;

    hr = pDevice->CreateBuffer( &m_BufferDesc, &m_SubResourceData, ppBuffer );
    if( FAILED( hr ) )
	{
        return hr;
	}	
	return S_OK;
}
void TDxBuffer::Apply(ID3D10Device* pDevice)
{
	/*UINT stride = sizeof( P3C_VERTEX );
    UINT offset = 0;
	pDevice->IASetVertexBuffers( 0, 1, &m_BufferVB.m_pBuffer, &stride, &offset );
	m_BufferVB.Apply();
	m_BufferIB.Apply();
	pDevice->IASetIndexBuffer( m_BufferIB.m_pBuffer, DXGI_FORMAT_R32_UINT, 0 );*/
}
bool TDxBuffer::Release()
{
	SAFE_RELEASE(m_pBuffer);
	return true;
}
TDxBuffer::TDxBuffer(void)
{
	m_pBuffer		= NULL;
	m_iCount			= 0;
}

TDxBuffer::~TDxBuffer(void)
{
	Release();
}
